package ch3;

public class BanJi {
    String name;
    String dirTeacher;
    String startDate;
    String[] stus = new String[30];

    public void add(String stuname) {
        for (int i = 0; i < stus.length; i++) {
            if (stuname.equals(stus[i])) {
                System.out.println("姓名有重复，加入失败！");
                break;
            }
            if (stus[i] == null) {
                stus[i] = stuname;
                break;
            }
        }
    }

    public void show() {
        System.out.println("学生信息");
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null)
                break;
            System.out.print(stus[i] + " ");
        }
    }

    public boolean searchName(String name) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null)
                return false;
            if (name.equals(stus[i]))
                return true;
        }
        return false;
    }

    public String find(int index) {
        if (stus[index] == null)
            return "未查到有效姓名";
        return stus[index];
    }

    public boolean update(String oldName, String newName) {
        for (int i = 0; i < stus.length; i++) {
            if (oldName.equals(stus[i])) {
                stus[i] = newName;
                break;
            }
            if (stus[i] == null) {
                stus[i] = newName;
                break;
            }
        }
        return false;
    }

    public int getNum() {
        int i = 0;
        for (; i < stus.length; i++) {
            if (stus[i] == null)
                //              System.out.println("班级目前有："+i+"人" );
                break;
        }
        return i;
    }
}
